<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="https://cdn.bootcss.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="https://s2.ax1x.com/2019/11/22/MTNIZF.png" type="image/x-icon"/>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <title>骁链</title>
</head>
<body>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h1 class="text-center" style="margin-top: 0.8em">
                骁链
            </h1>
            <hr/>
            <p class="text-center" style="margin-top: 3em">
                致力于免费的极速高并发短链接服务
            </p>
            <div class="text-center">
                <img src="https://s2.ax1x.com/2019/11/21/MIj44U.gif">
            </div>
            <div class="text-center">
                <p id="shorturl"></p>
            </div>
            <div style="text-align:center; margin-top: 1em">
                <form class="form-search" method="post" action="/">
                    <input id="url" name="url" type="text" placeholder="输入你的链接(例如http://www.baidu.com)"
                           class="input-xxlarge search-query text-center">
                    <button type="button" class="btn">生成</button>
                </form>
            </div>
            <div>
                <h3 class="text-center margin" style="margin-top: 2em;">使用方法</h3>
                <p>使用POST发送请求：<strong>http://zwxurl.top/你的网址</strong> 请记得带上http或者https</p>
                <h4>golang请求示例：</h4>
                <pre>
package main

import (
    "fmt"
    "net/http"
	"net/url"
	"io/ioutil"
)

func main() {
    data := make(url.Values)
    data["url"] = []string{"https://www.baidu.com"}

    res, err := http.PostForm("http://zwxurl.top/", data)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    defer res.Body.Close()
    body, err := ioutil.ReadAll(res.Body)
    fmt.Println(string(body))
}
                </pre>
                <h4>使用PHP请求示例</h4>
                <pre>

&lt;&#63;php
function send_post($url, $post_data) {
  	$postdata = http_build_query($post_data);
 	$options = array(
    'http' => array(
		'method' => 'POST',
		'header' => 'Content-type:application/x-www-form-urlencoded',
		'content' => $postdata,
		'timeout' => 15 * 60 // 超时时间（单位:s）
    )
  );
  	$context = stream_context_create($options);
 	$result = file_get_contents($url, false, $context);
  	return $result;
}
//测试
$post_data = array(
  	'url' => 'https://www.baidu.com',
);
echo send_post('http://zwxurl.top/', $post_data);
></pre>
            </div>
        </div>
    </div>
</div>
</body>
<script language="JavaScript">
    var isURL = function (str) {
        var strRegex = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])/;
        var re = new RegExp(strRegex);
        return re.test(str);
    }
    $("button").click(function () {
        if (isURL($("#url").val()) === true){
            $.ajax({
                url: "/",
                async: true,
                type: "post",
                data: {url: $("#url").val()},
                success: function (result) {
                    // alert(result);
                    $("#shorturl").text(result);
                }
            });
        } else {
            alert("链接不符合要求！")
        }
    })
</script>
</html>
